package entity;
import control.*;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.util.*;


public abstract class GameObj {

    private ArrayList<String> imgArrayList = new ArrayList<String>();//{"people1.PNG","people2.PNG","people3.PNG","people4.PNG","people5.PNG","people6.PNG","people7.PNG","people8.PNG"};
	private ArrayList<Image> imgsList = new ArrayList<Image>();
	private int imgIndex = 0;
	public int tempI = 0;
    private int x;
    private int y;
    private Image image;
    private int currentBoxNum = 0;

    private static ArrayList<GameObj> gameObj = new ArrayList<GameObj>();

    public GameObj(String imgs) {
        ImageIcon ii = new ImageIcon(this.getClass().getResource(imgs));
        image = ii.getImage();
		GameObj.gameObj.add(this);
        x = 40;
        y = 60;
    }
	public GameObj(String imgs, int cropWidth, int cropHeight) {
		imgsList = new Crop(imgs,cropWidth,cropHeight).getImages();
		image = imgsList.get(0);
		GameObj.gameObj.add(this);
		x = 40;
        y = 60;
	}
	//mutator
	public void setImageFiles(String [] imgs) {
		for(int i=0; i<imgs.length; i++) 
			imgArrayList.add(imgs[i]);
	}
	public void setNextImage() {
		if (imgsList.size() >0 ) {
			image = imgsList.get(imgIndex);
			imgIndex=(imgIndex+1)%imgsList.size();
			tempI++;
		}
	}
	public void setX(int x) {
		this.x = x;
	}
	public void setY(int y) {
		this.y = y;
	}
	public void setCurrentBoxNum(int num){
		this.currentBoxNum += num;
		if(currentBoxNum>=40)
			currentBoxNum-=40;
	}
	public void setDX(int dx) {
	}
	public void setDY(int dy) {
	}
	//accessor
	public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Image getImage() {
        return image;
    }

	public static ArrayList<GameObj> getGameObj() {
		return gameObj;
	}
	public static void setGameObj(GameObj go) {
		gameObj.add(go);
	}
	/**for Crop image*/
	public int getImgsListSize() {
		return imgsList.size();
	}
	public int getCurrentImgIndex() {
		return imgIndex-1;
	}
	
	public int getBoxNum(){
		return currentBoxNum;
	}

}
